﻿using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.Metadata.FieldElement;
using Kingdee.BOS.JSON;
using Kingdee.BOS.Util;
using System;
using System.ComponentModel;

namespace HX.HxDemo.BOS.Business.PlugIn25011606
{
    [Description("【表单插件】BeforeControlDataBinder"),HotUpdate]
    public class BeforeControlDataBinderFormPlugIn : AbstractDynamicFormPlugIn
    {
        public override void BarItemClick(BarItemClickEventArgs e)
        {
            base.BarItemClick(e);
            if (e.BarItemKey.EqualsIgnoreCase("MDCE_tb_test"))
            {
                this.View.UpdateView("F_MDCE_HX_Text");
                this.View.UpdateView("F_MDCE_HX_Decimal");
            }
        }

        public override void BeforeControlDataBinder(BeforeControlDataBinder e)
        {
            base.BeforeControlDataBinder(e);
            if (e.Control.Key.EqualsIgnoreCase("F_MDCE_HX_Text"))
            {
                var value = this.Model.GetValue("F_MDCE_HX_Text");
                e.BindValue = new JSONObject();
                e.BindValue[FieldAppearance.FS_VALUE] = string.Format("{0}-{1}", value, Context.UserName);
            }
            else if (e.Control.Key.EqualsIgnoreCase("F_MDCE_HX_Decimal"))
            {
                var value = Convert.ToDecimal(this.Model.GetValue("F_MDCE_HX_Decimal"));
                e.BindValue = new JSONObject();
                e.BindValue[FieldAppearance.FS_VALUE] = value * 100;
            }
        }
    }
}
